import {mongo} from "#nuxt-mongodb"
import {ObjectId} from "mongodb"

interface userIsVipInter{
    id: string,
    isVip:boolean
}

export default defineEventHandler(async(event:any)=>{
    const {id,isVip}:userIsVipInter = await readBody(event)
    
     // 将字符串 ID 转换为 ObjectId
    // console.log(objectId,phone,new_name)
    const objectId = new ObjectId(id)
    // 构建查询条件
    const query = { id:objectId,isVip: !isVip};
    console.log(isVip,query)
    // console.log(query,update)
    const result = await mongo.db().collection('userMes').updateOne(query,{$set: {isVip:!isVip?false:true}})
    console.log(result)
    if(result.matchedCount > 0){
        return {
            status: 200,
            data: result,
            message: `会员更改成功`
        }
    }else{
        return {
            status: 500,
            message: '会员更改失败'
        }
    }
    
})